<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>选项卡组件</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/style/admin.css" media="all">

</head>
<body>


<div class="layui-fluid" id="component-tabs">
    <div class="layui-row">
        <div class="layui-col-md12">
            <form id="myForm" action="{:url('config/webConfigdata')}" method="post"  enctype="multipart/form-data" class="layui-form form-horizontal">
                <div class="layui-card">
                    <div class="layui-card-header">网站配置</div>
                    <div class="layui-card-body">
                        <div class="layui-tab layui-tab-card">

                            <ul class="layui-tab-title">
                                {volist name="page_data" id="vo"}
                                <li {if condition="$key eq 0"} class="layui-this"{else/}{/if} >
                                <a data-toggle="tab" href="#tab-{$vo['group_id']}" aria-expanded="{if condition="$key eq 0"}true{else/}false{/if}">{$vo.group_title}</a>
                                </li>
                                {/volist}
                            </ul>

                            <div class="layui-tab-content">
                                {volist name="page_data" id="vo"}
                                <div id="tab-{$vo['group_id']}" {if condition="$key eq 0"}class="layui-tab-item layui-show"{else/}class="layui-tab-item"{/if} >
                                <div class="panel-body">

                                    {volist name="vo['config']" id="v"}
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">{$v.config_title}：</label>
                                        <div class="layui-input-block">
                                            <?php echo htmlspecialchars_decode($v['html']);?>
                                        </div>
                                    </div>
                                    {/volist}
                                </div>

                            </div>
                            {/volist}
                        </div>


                        <div class="layui-card-body">
                            <div class="layui-btn-container">
                                <button class="layui-btn layui-btn-normal">保存</button>
                            </div>
                        </div>
                    </div>
                </div>
        </div>
        </form>
    </div>
</div>


<script src="__STATIC__/layuiadmin/layui/layui.js"></script>
<script>

    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-component-form-group-date'
        });


    });


    layui.use(['form', 'layer','upload'], function () {
        var form = layui.form, layer = layui.layer,$= layui.jquery,upload = layui.upload;
        var info = {$info|raw};
        let id;
        // form.val("form", info);
        // if(info){
        //     $('#adPic' + id).attr('src',info.avatar);
        // }
        form.render();
        form.on('submit(submit)', function (data) {
            loading =layer.load(1, {shade: [0.1,'#fff']});
            $.post("", data.field, function (res) {
                console.log(res);
                layer.close(loading);
                layer.msg(res.msg, {time: 1800, icon: 1});
                if (res.code === 1) {
                    // setTimeout(function () {
                    //     history.go(-1);
                    // }, 1000);
                    location.reload();
                }else {
                    layer.msg(res.msg, {icon: 2, anim: 6, time: 1000});
                }
            });
        });

        $('.adBtn').click(function () {
            id = $(this).attr('data-id');
        });

        //普通图片上传
        var uploadInst = upload.render({
            elem: '.adBtn'
            ,url: '{:url("UpFiles/upload")}'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#adPic' + id).attr('src', result); //图片链接（base64）
                });
            },
            done: function(res){
                if(res.code>0){
                    $('#avatar' + id).val(res.url);
                }else{
                    //如果上传失败
                    return layer.msg('上传失败');
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    });
</script>
</body>
</html>
